﻿using Api1.Model;
using System;

namespace Api1.Service
{

    class SlidingDoorLogService : BaseService<SlidingDoorLog>
    {
        private static  SlidingDoorLogService  instance;

      
        private SlidingDoorLogService() {

        }
        public static SlidingDoorLogService GetInstance() {
            if (instance == null)
            {
                instance = new SlidingDoorLogService();
            }
            return instance;
        }
       /// <summary>
       /// 新增日志
       /// </summary>
       /// <param name="behavior"></param>
       /// <returns>新增的id</returns>
        public  long AddBehaviorLog(SlidingDoorLog slidingDoorLog) {
            return Insert(slidingDoorLog);
        }
       
        /// <summary>
        /// 新增进场刷卡日志
        /// </summary>
        /// <param name="interfaces"></param>
        /// <param name="flag">1 成功  ，2失败</param>
        /// <param name="error_msg"></param>
        /// <param name="brakemachine_no"></param>
        /// <returns></returns>
        public long AddSlidingDoor(Interfaces interfaces,int flag,string error_msg,string brakemachine_no,String door_name)
        {
            if(interfaces != null){
                var slidingDoorLog = new SlidingDoorLog
                {
                    Behavior_Type = 1,
                    Behavior_Status = flag,
                    Card_No = interfaces.Card_No,
                    Name = interfaces.Name,
                    Mobile = interfaces.Mobile,
                    Owner_Type = interfaces.Owner_Type,
                    Create_Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                    Error_Msg = error_msg,
                    Door_Code=brakemachine_no,
                    Door_Name=door_name
                };
               return   Insert(slidingDoorLog);
            }
            return 0;
        }
        /// <summary>
        /// 获取内门禁名称
        /// </summary>
        /// <returns></returns>
        public String GetDoorName(String brackemachine_no) {
            return ScalarForString(String.Format("select name from m_sliding_door where code='{0}'  limit 1 ",brackemachine_no));
        }
    }
}
